package pe.com.rix.taglib.view;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

public class ButtonBar extends BodyTagSupport{
	
	private static final long serialVersionUID = 1L;
	private String onClick;
	private String type;
	private String id;
	private String href;

	@Override
	public int doAfterBody() throws JspException {
		
		BodyContent bodycontent = getBodyContent();
        String body = bodycontent.getString();
		
		StringBuffer html = new StringBuffer();
		
		String Id = getId();
		String OnClick = getOnClick();
		String Type = getType();
		String Href = getHref();
		
		if(OnClick==null) OnClick = ""; else OnClick = " onclick='" + OnClick + "' "; 
		if(Id==null) Id = ""; else Id = " id='" + Id + "' ";
		if(Type==null || Type.equals("bar")) Type = " class='button-white' ";
		else if(Type.equals("caption"))
			Type = "  class='button-caption'";
		if(Href==null) Href = ""; else Href = " href='" + OnClick + "' ";
	
		html.append("<a " + Id + Href + OnClick + Type + " >");
		html.append("<span><em>");
		html.append(body);
		html.append("</em></span></a>");
		
		JspWriter out = bodycontent.getEnclosingWriter();
		try {
			out.print(html.toString());
		} catch (java.io.IOException ex) {
			throw new JspException(ex.getMessage());
		}
		return SKIP_BODY;
		
	}

	public String getOnClick() {
		return onClick;
	}

	public void setOnClick(String onClick) {
		this.onClick = onClick;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	public String getType() {
		return type;
	}
	
	public String getHref() {
		return href;
	}

	public void setHref(String href) {
		this.href = href;
	}

}
